package com.x.client.controller;

import com.alibaba.dubbo.config.annotation.Reference;

import com.x.client.rpc.ClientFeedbackRpcService;
import com.x.client.model.Feedback;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/clientFeedback")
public class ClientFeedbackController extends BaseController {


	@Reference
	private ClientFeedbackRpcService clientFeedbackRpcService;//车辆信息服务

	/**
	 * 新增意见反馈
	 * @param feedback
	 * @param bindingResult
	 * @return
	 */
	@RequestMapping(value = "/clientInsertFeedback", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel clientInsertFeedback(@Validated Feedback feedback, BindingResult bindingResult){
		if(bindingResult.hasErrors()){
			List<ObjectError> errors = bindingResult.getAllErrors();
			return new ResultModel(ResultCode.RESULT_FAIL, errors.get(0).getDefaultMessage());
		}
		feedback.setFeedbackCreateTime(this.getDate(0));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功", clientFeedbackRpcService.insertFeedBack(feedback));
	}


}
